package com.dream21th.common.exception.handler;

import com.dream21th.common.ComResp;
import com.dream21th.common.exception.WebException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@ControllerAdvice
public class WebExceptionHandler {

    @ExceptionHandler({ RuntimeException.class })
    private ComResp<?> processRuntimeException(RuntimeException e) {
        log.error("运行时异常{}", e);
        return new ComResp<>().result("500",e.getMessage());
    }

    @ExceptionHandler({ WebException.class })
    private ComResp<?> processWebException(WebException e) {
        log.error("系统错误{}", e);
        return new ComResp<>().result(e.getCode(),e.getMessage());
    }
}
